]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
screenshot: Add signals to ScreenshotUI
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Sat, 28 Oct 2023 22:18:53 +0000 (19:18 -0300)
committerMarge Bot <marge-bot@gnome.org>
Thu, 21 Dec 2023 17:59:17 +0000 (17:59 +0000)
These signals will let the yet to be introduced D-Bus method to
be notified of when either a screenshot has been taken, or if
the screenshot UI has been closed without taking a screenshot.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2999>

js/ui/screenshot.js

index 634f09feb43ad5a83e04359281bd87c913b45c31..bfe2f788099461fb4782712ceac1786a519ec0b5 100644 (file)
@@ -1060,6 +1060,10 @@ export const ScreenshotUI = GObject.registerClass({
             GObject.ParamFlags.READABLE,
             false),
     },
+    Signals: {
+        'screenshot-taken': {param_types: [Gio.File.$gtype]},
+        'closed': {},
+    },
 }, class ScreenshotUI extends St.Widget {
     _init() {
         super._init({
@@ -1663,6 +1667,8 @@ export const ScreenshotUI = GObject.registerClass({
         this._areaSelector.reset();
         for (const selector of this._windowSelectors)
             selector.reset();
+
+        this.emit('closed');
     }
 
     close(instantly = false) {
@@ -1845,7 +1851,7 @@ export const ScreenshotUI = GObject.registerClass({
 
     _onCaptureButtonClicked() {
         if (this._shotButton.checked) {
-            this._saveScreenshot();
+            this._saveScreenshot().catch(logError);
             this.close();
         } else {
             // Screencast closes the UI on its own.
@@ -1853,7 +1859,9 @@ export const ScreenshotUI = GObject.registerClass({
         }
     }
 
-    _saveScreenshot() {
+    async _saveScreenshot() {
+        let file = null;
+
         if (this._selectionButton.checked || this._screenButton.checked) {
             const content = this._stageScreenshot.get_content();
             if (!content)
@@ -1866,15 +1874,19 @@ export const ScreenshotUI = GObject.registerClass({
             if (!this._cursor.visible)
                 cursorTexture = null;
 
-            captureScreenshot(
-                texture, geometry, this._scale,
-                {
-                    texture: cursorTexture ?? null,
-                    x: this._cursor.x * this._scale,
-                    y: this._cursor.y * this._scale,
-                    scale: this._cursorScale,
-                }
-            ).catch(e => logError(e, 'Error capturing screenshot'));
+            try {
+                file = await captureScreenshot(
+                    texture, geometry, this._scale,
+                    {
+                        texture: cursorTexture ?? null,
+                        x: this._cursor.x * this._scale,
+                        y: this._cursor.y * this._scale,
+                        scale: this._cursorScale,
+                    }
+                );
+            } catch (e) {
+                logError(e, 'Error capturing screenshot');
+            }
         } else if (this._windowButton.checked) {
             const window =
                 this._windowSelectors.flatMap(selector => selector.windows())
@@ -1892,18 +1904,25 @@ export const ScreenshotUI = GObject.registerClass({
             if (!this._cursor.visible)
                 cursorTexture = null;
 
-            captureScreenshot(
-                texture,
-                null,
-                window.bufferScale,
-                {
-                    texture: cursorTexture ?? null,
-                    x: window.cursorPoint.x * window.bufferScale,
-                    y: window.cursorPoint.y * window.bufferScale,
-                    scale: this._cursorScale,
-                }
-            ).catch(e => logError(e, 'Error capturing screenshot'));
+            try {
+                file = await captureScreenshot(
+                    texture,
+                    null,
+                    window.bufferScale,
+                    {
+                        texture: cursorTexture ?? null,
+                        x: window.cursorPoint.x * window.bufferScale,
+                        y: window.cursorPoint.y * window.bufferScale,
+                        scale: this._cursorScale,
+                    }
+                );
+            } catch (e) {
+                logError(e, 'Error capturing screenshot');
+            }
         }
+
+        if (file)
+            this.emit('screenshot-taken', file);
     }
 
     async _startScreencast() {